import TWEEN from "tween";
import * as THREE from 'three';


// 获取摄像头在看什么位置
export const getCenterPosition = (CameraControls, distance = 50) => {
  const camera = CameraControls.current._camera
  const cameraPosition = camera.position;
  const cameraDirection = camera.getWorldDirection(new THREE.Vector3());
  return cameraPosition.clone().add(cameraDirection.multiplyScalar(distance));
}

// 缩小对象至消失
export const toLessen = (current, callback, time = 200) => {
  new TWEEN.Tween(current.scale).to({ x: 0.001, y: 0.001, z: 0.001 }, time).onComplete(() => {
    current.visible = false
    if (callback) callback()
  }).start();
}
// 显示对象并放大至正常
export const toRecover = (current, callback, time = 200) => {
  current.visible = true
  new TWEEN.Tween(current.scale).to({ x: 1, y: 1, z: 1 }, time).onComplete(() => {
    if (callback) callback()
  }).start();
}

export const changeCardByName = (name, type, words) => {
  const newmap = {
    'blue': {
      color: '#3bcaff',
      icon_bg: '/img/card_blue.png',
      card_bg: 'url(/img/card_blue_conent.png) center center / cover no-repeat',
    },
    'yellow': {
      color: '#ffd83b',
      icon_bg: '/img/card_yellow.png',
      card_bg: 'url(/img/card_yellow_conent.png) center center / cover no-repeat',
    },
    'orange': {
      color: '#ff8e3b',
      icon_bg: '/img/card_orange.png',
      card_bg: 'url(/img/card_orange_conent.png) center center / cover no-repeat',
    },
    'red': {
      color: '#ef3a3a',
      icon_bg: '/img/card_red.png',
      card_bg: 'url(/img/card_red_conent.png) center center / cover no-repeat',
    },
  }
  if (newmap[type]) {
    document.getElementById(name + '_svg').setAttribute("fill", newmap[type].color);
    document.getElementById(name + '_icon_bg').src = newmap[type].icon_bg
    document.getElementById(name + '_card_bg').style.background = newmap[type].card_bg
    document.getElementById(name + '_card_span').innerHTML = words;
  }
}